import sharp from 'sharp'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
import { mkdirSync, existsSync } from 'fs'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const rootDir = join(__dirname, '..')
const iconsDir = join(rootDir, 'public', 'icons')
const svgPath = join(iconsDir, 'icon.svg')

// Ensure icons directory exists
if (!existsSync(iconsDir)) {
  mkdirSync(iconsDir, { recursive: true })
}

// Convert SVG to PNG for different sizes
const sizes = [16, 48, 128]

async function convertSvgToPng() {
  try {
    for (const size of sizes) {
      const pngPath = join(iconsDir, `icon-${size}.png`)
      await sharp(svgPath)
        .resize(size, size, {
          fit: 'contain',
          background: { r: 255, g: 255, b: 255, alpha: 0 }
        })
        .png()
        .toFile(pngPath)
      console.log(`✅ Created ${pngPath}`)
    }
    console.log('✅ All PNG icons created successfully!')
  } catch (error) {
    console.error('❌ Error converting SVG to PNG:', error.message)
    process.exit(1)
  }
}

convertSvgToPng()

